package com.aq.sales.business.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.aq.sales.business.intf.RolesBO;
import com.aq.sales.entity.Opportunity;
import com.aq.sales.entity.Role;
@Service
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public class RolesBOImpl extends CommonBOImpl<Role> implements
		RolesBO<Role> {

		@Override
	public List<Role> findAll(int accId) {
		Query qry=getCurrentSession().createQuery("from Role where accId=:accId");
		qry.setInteger("accId", accId);
		return qry.list();
	}
	

	@Override
	public int insert(Role obj) {
		getCurrentSession().save(obj);
		return 0;
	}

	@Override
	@Transactional
	public int update(Role obj) {
		getCurrentSession().saveOrUpdate(obj);
		return 0;
	}

	@Override
	public int delete(Role obj) {
		getCurrentSession().delete(obj);
		return 0;
	}


	@Override
	public Role findById(int id,int accId) {
		throw new RuntimeException("This method is not Supported");
	}

	@Override
	public Role findById(int id) {
		Query qry=getCurrentSession().createQuery("from Role where id=:id");
		qry.setInteger("id", id);
		return (Role)qry.uniqueResult();
	}

	@Override
	public List<Role> getRoles(int accId) {
		return findAll(accId);
	}
	
	@Override
	public List<Role> query(String where,int accId) {
		String sql="from Role where "+where+" AND accId=:accId";
		Query qry=getCurrentSession().createQuery(sql);
		qry.setInteger("accId", accId);
		return qry.list();
	}
}
